home *** CD-ROM | disk | FTP | other *** search
/ MacHack 2000 / MacHack 2000.toast / pc / The Hacks / Softshoe / Lisa's Mac Parts / Heap / HeapLink.cp < prev    next >
Text File  |  2000-06-23  |  986b  |  59 lines

  1. // HeapLink.cp
  2. #define HeapLink_cp
  3.  
  4. #ifndef HeapLink_h
  5. #include "HeapLink.h"
  6. #endif
  7. #ifndef Heap_h
  8. #include "Heap.h"
  9. #endif
  10. #ifndef Swap_h
  11. #include "Swap.h"
  12. #endif
  13. #ifndef Heap_h
  14. #include "Heap.h"
  15. #endif
  16.  
  17. template < class Element >
  18. HeapLink<Element>::HeapLink( Element *e )
  19.   : heap( 0 ),
  20.      body( e ),
  21.      path( 0 )
  22.   {
  23.     children[0] = 0;
  24.     children[1] = 0;
  25.   }
  26.  
  27. template < class Element >
  28. HeapLink<Element>::~HeapLink()
  29.   {
  30.     if ( heap != 0 )
  31.         heap->Remove( *this );
  32.     Assert( heap == 0 );
  33.   }
  34.  
  35. template < class Element >
  36. void HeapLink<Element>::SwapWith( LinkType& r )
  37.   {
  38.     Assert( heap == r.heap );
  39.  
  40.     Swap( path, r.path );
  41.     Swap( children[0], r.children[0] );
  42.     Swap( children[1], r.children[1] );
  43.   }
  44.  
  45. template < class Element >
  46. bool HeapLink<Element>::operator<=( const LinkType& r ) const
  47.   {
  48.     Assert( heap == r.heap );
  49.     Assert( heap != 0 );
  50.     
  51.     Comparator below( heap->Below() );
  52.     Assert( below != 0 );
  53.     
  54.     Assert( !Null() );
  55.     Assert( !r.Null() );
  56.     
  57.     return (body->*below)(*r.body);
  58.   }
  59.